use serde::{Deserialize, Serialize};

use crate::{BlockId, TransactionId, transaction::Transaction};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct WalletTx {
    // tx_id: TransactionId,
    tx: Transaction,

    belong_to_block: Option<BlockId>,
    // merkle_tree: Vec<BlockChainHash>,
    _from_me: bool,
    spent: bool,
}

impl WalletTx {
    pub fn new(tx: &Transaction) -> Self {
        Self {
            tx: tx.clone(),
            belong_to_block: None,
            _from_me: false,
            spent: false,
        }
    }

    pub fn get_tx(&self) -> &Transaction {
        &self.tx
    }

    pub fn calc_tx_id(&self) -> TransactionId {
        self.tx.calc_tx_id()
    }

    pub fn is_final(&self, block_time: i64, best_hight: u32) -> bool {
        self.tx.is_final(block_time, best_hight)
    }
    // pub fn get_tx(&self) -> &Transaction {
    //     &self.tx
    // }
    // pub fn get_tx_id(&self) -> TransactionId {
    //     self.tx.calc_tx_id()
    // }
    pub fn get_belong_to_block(&self) -> Option<&BlockId> {
        self.belong_to_block.as_ref()
    }

    pub fn is_spent(&self) -> bool {
        self.spent
    }

    pub fn set_spent(&mut self) {
        self.spent = true;
    }
}
